package com.example.bloodbankproject;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class RequestFriendActivity extends Activity {
	private EditText mEText1, mEText2, mEText3,mEText4,mEText5;
	private String mUser1, mUser2, mUser3,mUser4,mUser5;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.requestfriend);
		mEText1 = (EditText) findViewById(R.id.ed1);
		mEText2 = (EditText) findViewById(R.id.ed2);
		mEText3 = (EditText) findViewById(R.id.ed3);
		mEText4 = (EditText) findViewById(R.id.ed4);
		mEText5 = (EditText) findViewById(R.id.ed5);
	}
              
	public void buttonRequestFriend(View v) {

		mUser1 = mEText1.getText().toString();
		mUser2 = mEText2.getText().toString();
		mUser3 = mEText3.getText().toString();
		mUser4 = mEText4.getText().toString();
		mUser5 = mEText5.getText().toString();
		
		
		StringBuffer sb = new StringBuffer();
		sb.append(mUser1).append(",").append(mUser2).append(",").append(mUser3).append(",").append(mUser4).append(",").append(mUser5);
		Log.i("NCS", "EmailId's are" + sb.toString());

		Properties props = new Properties();
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.port", "465");

		Session session = Session.getDefaultInstance(props,
				new javax.mail.Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
						return new PasswordAuthentication(
								"android.bloodbank@gmail.com", "bloodbank@123");
					}
				});

		try {
			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress("android.bloodbank@gmail.com"));
			message.setRecipients(Message.RecipientType.TO, InternetAddress
					.parse(sb.toString()));
			message.setSubject("Give Blood Give Life");
			message.setContent("http://www.bloodbankindia.net/",
					"text/html; charset=utf-8");

			Transport.send(message);

		} catch (MessagingException e) {
			
			Log.i("NCS", "Exception is are" + e.getMessage());
			
			throw new RuntimeException(e);
		}
	}

}
